import { Nodes } from '@knno/dom';
import { Button as UIButton, ButtonType, IconPos } from '../components/button/button';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, isBool, isStr, jsxBuild } from './utils';

export { UIButton };

interface ButtonProps extends JSXProps<UIButton> {
	type?: ButtonType;
	icon?: string;
	iconPos?: IconPos;
	text?: string;
	value?: string;
	menu?: boolean;
	disabled?: boolean;
	checked?: boolean;
}

const ATTRS: AttrCheck = {
	type: isStr,
	icon: isStr,
	iconPos: (v: unknown) => v === 'left' || v === 'top',
	text: isStr,
	value: isStr,
	disabled: isBool,
	menu: isBool,
	checked: isBool,
};

export function Button(props: ButtonProps, children: Nodes[]): UIButton {
	return jsxBuild(new UIButton(), props, children, ATTRS);
}
